package com.kdl.webconfig.controller;


import com.kdl.webconfig.business.PicConfigBusiness;
import com.kdl.webconfig.vo.BaseRespVO;
import com.kdl.webconfig.vo.PageVO;
import com.kdl.webconfig.vo.config.PicConfigDetailVO;
import com.kdl.webconfig.vo.config.PicConfigQueryReq;
import com.kdl.webconfig.vo.config.PicConfigSaveReq;
import com.kdl.webconfig.vo.config.PicConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 图片配置
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wcj
 * @since 2022-09-04
 */
@RestController
@RequestMapping("/webconfig/picConfig")
@Api(value = "图片配置管理接口", tags = {"图片配置"})
public class PicConfigController {

    @Autowired
    private PicConfigBusiness picConfigBusiness;

    @GetMapping( "test")
    @ApiOperation("test")
    public String test(){
        return "aaa";
    }

    @PostMapping("/page")
    @ApiOperation(value = "图片配置列表")
    public BaseRespVO<PageVO<PicConfigVO>> page(@RequestBody @Valid PicConfigQueryReq picConfigReq){
        PageVO<PicConfigVO> page = picConfigBusiness.page(picConfigReq);
        return BaseRespVO.success(page);
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "图片配置新增或更新")
    public BaseRespVO<Boolean> saveOrUpdate(@RequestBody@Valid PicConfigSaveReq picConfigSaveReq){
        Boolean b = picConfigBusiness.saveOrUpdate(picConfigSaveReq);
        return BaseRespVO.success(b);
    }

    @PostMapping("/delete/{id}")
    @ApiOperation(value = "图片配置删除")
    public BaseRespVO<Boolean> delete(@PathVariable Integer id){
        Boolean b = picConfigBusiness.deleteByPicId(id);
        return BaseRespVO.success(b);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation(value="图片配置详情")
    public BaseRespVO<PicConfigDetailVO> detail(@PathVariable Integer id){
        PicConfigDetailVO picConfigDetailVO = picConfigBusiness.detail(id);
        return BaseRespVO.success(picConfigDetailVO);
    }

}

